package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

import DataObjects.StandardMenuRightList;

public class AddNewStandardMenu {

	
	private Vector<StandardMenuRightList> menuDetails;
	private Vector<String> menuDetails1;
	private int i=0;
	private int statusRecipe;
	private int status=0;
	
	public AddNewStandardMenu(Vector<StandardMenuRightList> menuDetail,Vector<String> menuDetail1)
	{
		
		this.menuDetails=menuDetail;
		this.menuDetails1=menuDetail1;
		
	}
	
	public void saveNewStandardMenu()
	{
		SQLConnection sc=new SQLConnection();
		
				
		try {
			    			
					PreparedStatement ps2 = sc.getConnection().prepareStatement("INSERT INTO menu (Mid,Mname,Mstatus,Mtype) values(?,?,?,'simple');");	
					
					
					sc.getConnection().setAutoCommit(false);
					ps2.setString(1,(String) menuDetails1.get(0));
					ps2.setString(2,(String) menuDetails1.get(1));
					ps2.setString(3,(String) menuDetails1.get(2));
					ps2.executeUpdate();
					sc.getConnection().commit();
					ps2.close();
					
					while(i<menuDetails.size())
					{
						PreparedStatement ps1 = sc.getConnection().prepareStatement("INSERT INTO recipe_in_menu (Mid,Rid,price,isSelectable,rquantity) values(?,?,?,?,?);");	
						
						sc.getConnection().setAutoCommit(false);
						ps1.setString(1,(String) menuDetails1.get(0));
						ps1.setString(2,Integer.toString( menuDetails.get(i).getRid()));
						ps1.setString(3,Integer.toString( menuDetails.get(i).getPrice()));
						ps1.setString(4,Integer.toString( menuDetails.get(i).getIsSelectable()));
						ps1.setString(5,Integer.toString( menuDetails.get(i).getQuantity()));
						ps1.executeUpdate();
						sc.getConnection().commit();
						ps1.close();
						i++;
						
					}
					
						
				sc.getConnection().close();	
			    status=1;		
		 }
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		                       }
} 





	public int getStatus() {
		return status;
	}





	public void setStatus(int status) {
		this.status = status;
	}
		
}
